package com.ics.atable.chat.model.dto;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;

/**
 * 意图识别结果 序列化类
 *
 * @author haohongbin
 */
@Data
public class IntentExtract {

    private Boolean change;

    private String output;

    // 添加无参构造函数
    public IntentExtract() {}

    // 或者使用 @JsonCreator 注解指定构造函数
    @JsonCreator
    public IntentExtract(@JsonProperty("change") boolean change,
                         @JsonProperty("output") String output) {
        this.change = change;
        this.output = output;
    }

    @JsonCreator
    public static IntentExtract fromJsonString(String json) {
        try {
            ObjectMapper mapper = new ObjectMapper();
            return mapper.readValue(json, IntentExtract.class);
        } catch (Exception e) {
            throw new IllegalArgumentException("Failed to parse JSON: " + json, e);
        }
    }
}
